#include "../include/BaseLib.hpp"

namespace BaseLib
{
    /*最大事件数量*/
    const int g_max_event_num = 1024;
    /*服务器地址*/
    const char* g_server_address = "127.0.0.1";
    /*服务器端口号*/
    const int g_server_port = 8787;

    int set_noblockint(int fd)
    {
        int old_option = fcntl(fd,F_GETFL);
        int new_option = old_option | O_NONBLOCK;
        int ret = fcntl(fd,F_SETFL,new_option);
        if(ret < 0)
        {
            perror("fcntl");
            return -1;
        }
        return new_option;
    }

    int add_epoll_fd(int epollfd,int fd)
    {
        epoll_event event;
        event.data.fd = fd;
        event.events = EPOLLIN | EPOLLET;
        int ret = epoll_ctl(epollfd,EPOLL_CTL_ADD,fd,&event);
        if(ret < 0) perror("epoll_ctl");
        ret = set_noblockint(fd);
        return ret;
    }
}